﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HZ.Supervise.Web.Common
{
    public partial class FindAllHospital : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                dataBind();
                if (IsPostBack)
                {
                   bindList();
                }
        }

        /// <summary>
        /// 绑定List控件集合
        /// </summary>
        private void bindList()
        {
            string[] hosName = this.HosName.Value.Split(',');
            string[] hosId = this.HosId.Value.Split(',');
            this.ListHos.Items.Clear();
            for (int i = 0; i < hosName.Length; i++)
            {
                if (hosName[i].Equals(""))
                {
                    return;
                }
                ListItem item = new ListItem();
                item.Text = hosName[i];
                item.Value = hosId[i];
                this.ListHos.Items.Add(item);
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void dataBind()
        {
            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            string where = "";
            string areaID = "";

            int i;
            if (!string.IsNullOrEmpty(this.txtHosName.Text))
            {
                where = this.txtHosName.Text;
            }
            if (!CurrentAccount.GetUser().Org.Area.AreaID.Equals(Constants.CURRENT_DEPLOY_AREAID))
            {
                areaID = CurrentAccount.GetUser().Org.Area.AreaID;
            }
            DataTable dt = pre.GetHospital(where, "X"+areaID, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out i);
            AspNetPager1.RecordCount = i;
                gvwHosList.DataSource = dt;
                gvwHosList.DataBind();
        }

        protected void btnQery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            dataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            dataBind();
        }

    }
}
